package com.yanchangapp.ui.activity.purchase.approve;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.yanchangapp.R;
import com.yanchangapp.adapter.GoodsInnerAdapter;
import com.yanchangapp.model.bean.GoodsSupplierBean;
import com.zxl.baselib.ui.base.BaseActivity;
import com.zxl.baselib.ui.base.BasePresenter;
import com.zxl.baselib.util.ui.UIUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * 供应商列表选择
 *
 * 提供用户选择对用供应商跳转对应的详情页并通过订单ID获取详情信息
 *
 */
public class GoodsInnerSupplierActivity extends BaseActivity {

    @BindView(R.id.ivToolbarNavigation)
    ImageView ivToolbarNavigation;
    @BindView(R.id.vToolbarDivision)
    View vToolbarDivision;
    @BindView(R.id.tvToolbarTitle)
    TextView tvToolbarTitle;
    @BindView(R.id.tvInnerTitle)
    TextView tvInnerTitle;
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;

    private GoodsInnerAdapter mGoodsInnerAdapter;

    private List<GoodsSupplierBean> mSupplierBeans = new ArrayList<>();
    private String mBuyerName;


    private static final String BUYER_NAME = "buyerName";
    private static final String BEAN = "bean";
    public static void show(Activity activity,String buyerName,List<GoodsSupplierBean> mSupplierBeans){
        Intent intent = new Intent(activity,GoodsInnerSupplierActivity.class);
        Bundle bundle = new Bundle();
        bundle.putSerializable(BEAN,(Serializable) mSupplierBeans);
        bundle.putString(BUYER_NAME,buyerName);
        intent.putExtras(bundle);
        activity.startActivity(intent);
    }

    @Override
    protected void init() {
        if (getIntent() != null){
            Bundle bundle = getIntent().getExtras();
            if (bundle != null) {
                mBuyerName = bundle.getString(BUYER_NAME);
                mSupplierBeans.clear();
                mSupplierBeans = (List<GoodsSupplierBean>) bundle.getSerializable(BEAN);
            }else {
                finish();
            }

        }else {
            finish();
        }
    }

    @Override
    protected int provideContentViewId() {
        return R.layout.activity_goods_inner_supplier;
    }

    @Override
    protected BasePresenter createPresenter() {
        return null;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        tvToolbarTitle.setText(getString(R.string.inner_supplier_toolbar,mBuyerName));
        tvInnerTitle.setText(getString(R.string.inner_supplier_title,mSupplierBeans.size()));
        initAdapter();
    }

    private void initAdapter() {
        recyclerView.setLayoutManager(new LinearLayoutManager(this,LinearLayoutManager.VERTICAL,false));
        mGoodsInnerAdapter = new GoodsInnerAdapter(R.layout.item_inner_supplier_list,mSupplierBeans);
        recyclerView.setAdapter(mGoodsInnerAdapter);
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initListener() {
        // 点击返回进行页面回退
        ivToolbarNavigation.setOnClickListener(v -> finish());

        mGoodsInnerAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                PassApprovePassDetailActivity.show(GoodsInnerSupplierActivity.this,mSupplierBeans.get(position).getOrderId());
            }
        });
    }

}
